﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq.Expressions;

namespace Project.Common
{
    /// <summary>
    /// 摘自：ASP.NET Design Patterns - ASP.NET MVC Case Study Starter Kit
    /// 获取对象的属性名称
    /// </summary>
    public static class PropertyNameHelper
    {
        // ResolvePropertyName 改为：Resolve
        public static string Resolve<T>(Expression<Func<T, object>> expression)
        {
            var expr = expression.Body as MemberExpression;
            if (expr == null)
            {
                var u = expression.Body as UnaryExpression;
                expr = u.Operand as MemberExpression;
            }
            return expr.ToString().Substring(expr.ToString().IndexOf(".") + 1);
        }
    }
}
